home *** CD-ROM | disk | FTP | other *** search
- /*
- This simple app demonstrates how to force the preview enabled mode by install a modal
- dialog filter proc in the CustomGetFilePreview routine. This works with System 7 call.
- You should check out the Standard File documentation in Inside Mac: Files as well.
-
- This sample is based on CustomPreview code in QT1.0 CD.
-
- Larry Lai
- Developer Technical Support
- Apple Computer, Inc.
-
- Feburary 3, 1995
-
- */
-
- #include "ImageCompression.h"
- #include <Files.h>
- #include <GestaltEqu.h>
- #include <StandardFile.h>
- #include <Controls.h>
-
- // some constants for the buttons we added to the dialog
- enum {
- buttonPictureFiles = 16,
- buttonAllFiles
- };
-
- // prototypes
- void updateFileButtons(DialogPtr d, Boolean showAllFiles);
- pascal short myDialogHook7(short item, DialogPtr d, Boolean *showAllFiles);
- pascal Boolean myFileFilter7(CInfoPBPtr pb, Boolean *showAllFiles);
- Boolean doCustom7(FSSpec *fss);
- pascal Boolean myModalFilter7(DialogPtr theDlg, EventRecord *theEvent, short *itemHit, Boolean *showAllFiles);
-
-
- /*
- resource id numbers of the dialogs.
-
- Note that both of these dialogs have a Dialog Color Table ('dctb')
- resource as well. This is so that the window used by Standard File will
- be a color window. In some cases this may allow previews to display more
- accurate colors. On System 7, owing to a bug in the PopUp menu CDEF, it
- is necessary to make it a color window, or else the CDEF draws incorrectly
- in some cases (when the port origin is not (0,0)).
- */
- #define Custom7DialogID (129)
-
- // a global to keep track of whether we are showing all files or just pictures
- Boolean gShowAllFiles = false;
-
- Boolean doCustom7(FSSpec *fss); // returns true if a file was selected
-
- /*
- routine shared by both the system 6 and system 7 filters.
- this routine simply hilites the two radio buttons depending on
- the value of the "showAllFiles" parameter.
- */
- void updateFileButtons(DialogPtr d, Boolean showAllFiles)
- {
- short kind;
- Rect r;
- ControlHandle ch;
-
- GetDItem(d, buttonPictureFiles, &kind, (Handle *)&ch, &r);
- SetCtlValue(ch, !showAllFiles);
-
- GetDItem(d, buttonAllFiles, &kind, (Handle *)&ch, &r);
- SetCtlValue(ch, showAllFiles);
- }
-
-
- /*****************************************************
-
- System 7 Preview code
-
- Note that the system 7 standard file interface allows for a
- YDPtr (YourDataPtr) to be passed to all filters. This means
- that the filter procs do not need to use any global
- variables.
-
- ******************************************************/
-
- pascal short myDialogHook7(short item, DialogPtr d, Boolean *showAllFiles)
- {
-
- switch (item) {
- case sfHookFirstCall:
- // put buttons in correct initial state
- updateFileButtons(d, *showAllFiles);
- break;
- case buttonPictureFiles:
- if (*showAllFiles) {
- *showAllFiles = false;
- updateFileButtons(d, *showAllFiles);
- item = sfHookRebuildList; // force standard file to redisplay list
- }
- break;
- case buttonAllFiles:
- if (!*showAllFiles) {
- *showAllFiles = true;
- updateFileButtons(d, *showAllFiles);
- item = sfHookRebuildList; // force standard file to redisplay list
- }
- break;
- }
-
- return(item);
- }
-
- pascal Boolean myFileFilter7(CInfoPBPtr pb, Boolean *showAllFiles)
- {
- /*
- return false to indicate that file/directory should be displayed.
- note that unlike the system 6 version of this filter, you can suppress the
- display of directories as well as files. thus the extra check for directories
- is required below
- */
-
- if (*showAllFiles)
- return(false);
- else {
- if (pb->hFileInfo.ioFlFndrInfo.fdType == 'PICT')
- return(false);
- else
- return(!(pb->hFileInfo.ioFlAttrib & 16)); // directory
- }
- }
-
- pascal Boolean myModalFilter7(DialogPtr theDlg, EventRecord *theEvent, short *itemHit, Boolean *showAllFiles)
- {
- short iType;
- Handle iHandle;
- Rect iRect;
- short c;
-
- *showAllFiles = true;
-
- /*
- handle null event, set the control value of show preview checkbox to 1 if it is
- unchecked. event from ModalDialog will pass here first before it gets handed to
- the standard file package filter
-
- */
-
- switch (theEvent->what) {
- case nullEvent:
- *itemHit = 15; // 15 is the resource ID of show preview checkbox
- GetDItem(theDlg, *itemHit, &iType, &iHandle, &iRect);
- c = GetCtlValue ((ControlHandle) iHandle);
-
- if (!c){
- SetCtlValue((ControlHandle)iHandle, true);
- }
- else
- return false;
-
- return true;
- break;
- default:
- return false;
- }
- }
-
- Boolean doCustom7(FSSpec *fss)
- {
- Point where;
- StandardFileReply reply;
-
- where.h = where.v = -2; // center the dialog on the "best" screen
-
- CustomGetFilePreview((FileFilterYDProcPtr)myFileFilter7, -1, 0, &reply, Custom7DialogID, where,
- (DlgHookYDProcPtr)myDialogHook7, (ModalFilterYDProcPtr)myModalFilter7, 0, 0, &gShowAllFiles);
-
- return(reply.sfGood);
- }
-
- /*
- Simple main routine.
-
- */
- void main(void)
- {
- long response;
- FSSpec fileSpec;
-
- // initialize the world
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone();
-
- // must have image compression manager to use Standard Preview
- if (Gestalt(gestaltCompressionMgr, &response))
- return;
-
- // system 7 calls are only available if the standard file selectors 5 through 8 are around
- if ( (Gestalt(gestaltStandardFileAttr, &response) == noErr) &&
- BitTst((Ptr)&response, 31 - gestaltStandardFile58) )
- doCustom7(&fileSpec);
- }
-